/*
Work in this file belongs to BATTERY MANAGEMENT group. 
Other groups are not allowed to make changes on this file. 

During development, you can use your own test code that
includes your own setup() and loop() functions but they 
should not be included when you are submitting your changes. 
*/
void battery(){
bmCalculateBattery;
bmRealBattery;

}

void bmCalculateBattery(int distance, int vspeed){     // function coefficients that will lead to a battery decrease.
  float consumption; 
  consumption = 1 + (pmPassengerCount * 0.25);   //  Person count is directly proportional to battery decrease, as shown on the equation.
  consumption = consumption * distance; //  If distance count increases, battery decreases according to the equation. On every step the factors that lead to the battery decrease are added.if the car goes 10meters with 0 person and 5km/h it consumes 10% of battery charge
  consumption = consumption * (vspeed * vspeed); // Higher speed means higher battery consumption. 
  consumption /= 25;                             // speed normalization i made on this step.
  bmBatteryCapacity -= consumption;
  bmBatteryCapacityforDrive = 100 * bmBatteryCapacity; // variable for Drive Group
  //raise battery alarm if charge dips below 10%
  if(bmBatteryCapacity < 10){
    bmBatteryAlarm = true;
  }
}

void bmRechargeBattery(){
  bmBatteryAlarm = false; 
  bmBatteryCapacity = 100;
}


void bmRealBattery(){  
  digitalWrite(bmled, LOW);                //set led low
  bmvalue = analogRead(bmanalogInput);       // read the value on analog input
  bmvout = (bmvalue * 5.0) / 1024.0;         //some calculations for calculating Vin
  bmvin = bmvout / (bmR2/(bmR1+bmR2));             //some calculations for calculating Vin
 // vin -=0.07;                          //normalization if needed
  if(bmvin>=8.4){
         bmpercentage= 100;                // if Vin >8.4 then percentage is 100
   }
  else if(bmvin<7.4){
         bmpercentage = 0;
         digitalWrite(bmled, HIGH);         // if Vin < 7.4 then charge led is on and percentage is 0
   }
  else{
        bmpercentage = bmvin-7.4;              //if 8.4 >Vin>7.4  percentage calculation.
        bmpercentage = bmpercentage*100;
   }
   bmpercentageforDrive = bmpercentage;   // for drive group 
  // sleep...
//  delay(100);                          // i don't think we will need delay func. 
}


